package model

import (
	"time"

	"github.com/jinzhu/gorm"
)

// Author 作者结构体
type Author struct {
	gorm.Model
	Name    string `gorm:"type:varchar(64);not null;column:name"`
	Profile string `gorm:"type:text;not null;column:profile"`
	Works   string `gorm:"type:varchar(64);not null;column:works"`
	Avatar  string `gorm:"type:varchar(255);column:avatar"`
}

// AuthorSerializer 序列化结构体
type AuthorSerializer struct {
	ID        uint       `json:"id"`
	CreatedAt time.Time  `json:"createdTime"`
	UpdatedAt time.Time  `json:"updated_at"`
	DeletedAt *time.Time `json:"deleted_at"`
	Name      string     `json:"name"`
	Profile   string     `json:"profile"`
	Works     string     `json:"works"`
	Avatar    string     `json:"avatar"`
}

// Serializer 返回作者json数据
func (a *Author) Serializer() AuthorSerializer {
	return AuthorSerializer{
		ID:        a.ID,
		CreatedAt: a.CreatedAt,
		UpdatedAt: a.UpdatedAt,
		DeletedAt: a.DeletedAt,
		Name:      a.Name,
		Profile:   a.Profile,
		Works:     a.Works,
		Avatar:    a.Avatar,
	}
}

type PoetrySerializer struct {
	ID        uint       `json:"id"`
	CreatedAt time.Time  `json:"createdTime"`
	Title     string     `json:"title"`
	Dynasty   string     `json:"dynasty"`
	Name      string     `json:"name"`
	Content   string     `json:"content"`
	Tags      string     `json:"tags"`
}

type Poetry struct {
	gorm.Model
	Title   string `gorm:"type:varchar(64);not null;column:title"`
	Dynasty string `gorm:"type:varchar(64);not null;column:dynasty"`
	Name    string `gorm:"type:varchar(64);not null;column:name"`
	Content string `gorm:"type:text;not null;column:content"`
	Tags    string `gorm:"type:varchar(255);not null;column:tags"`
}

func (p *Poetry) Serializer() PoetrySerializer {
	return PoetrySerializer{
		ID:        p.ID,
		CreatedAt: p.CreatedAt,
		Title:   	 p.Title,
		Dynasty:   p.Dynasty,
		Name:      p.Name,
		Content:   p.Content,
		Tags:      p.Tags,
	}
}

func (p *Poetry) Create() {}
